package com.mxpio.erp.workshop.policy;

import org.apache.commons.collections4.CollectionUtils;

import com.mxpio.erp.common.order.policy.OrderContext;
import com.mxpio.erp.common.order.policy.OrderPolicy;

/**
 * 根据策略执行生产订单
 *
 */
public abstract class AbstractMoPolicy implements OrderPolicy {
	
	@Override
	public void apply(OrderContext context) {
		if(beforeExecute(context)) {
			execute(context);
			afterExecute(context);
		} else {
			if(CollectionUtils.isEmpty(context.getErrors())) {
				context.addError("前置校验不通过");
			}
		}
	}
	
	public abstract void execute(OrderContext context);
	
	public abstract boolean beforeExecute(OrderContext context);

	public abstract void afterExecute(OrderContext context);

}
